package Day5;

import java.util.Scanner;

public class Main {

        public static int FindGreatestSumOfSubArray(int[] array) {
            int max = Integer.MIN_VALUE, sum = 0;
            for(int i = 0; i < array.length; ++i){
                sum += array[i];         //累加
                if(sum > max)
                    max = sum; //
                if(sum < 0)
                    sum = 0;
            }
            return max;
        }

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        String s = scanner.nextLine();
        int[] arr = new int[n];
        String[] strings = s.split(" ");

        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(strings[i]);
        }

        int maxSum = FindGreatestSumOfSubArray(arr);

        System.out.println(maxSum);
    }

    public static void main1(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String A = scanner.next();
        String B = scanner.next();

        int ret = 0;
        int IndexA = A.length() - 1;

        //首尾单独判断
        if (checkPalindrome(A + B))
            ret++;
        if (checkPalindrome(B + A))
            ret++;

        while (IndexA != 0) {

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(A.substring(0,IndexA));
            stringBuilder.append(B);
            stringBuilder.append(A.substring(IndexA, A.length()));

            if (checkPalindrome(stringBuilder.toString()))
                ret++;

            IndexA--;
        }

        System.out.print(ret);

    }

    public static boolean checkPalindrome (String s) {

        int left = 0;
        int right = s.length() - 1;

        while (left <= right) {
            //相等就继续遍历
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            } else {
                return false;
            }
        }

        return true;
    }

}
